package com.dly.blog.domain.ro;

import com.dly.blog.domain.GptSessionContent;
import com.dly.blog.domain.dto.MessageContentDto;
import com.dly.blog.domain.enums.ChatType;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ChatGptRO implements Serializable {

    @Schema(description = "一组消息")
    @NotEmpty(message = "聊天消息")
    private List<MessageContentDto> messages;

    @Schema(description = "聊天类型")
    @NotNull(message = "聊天类型")
    private ChatType chatType;

    public List<GptSessionContent> cover(String sessionId){
        return this.messages.stream().map(messageContentDto -> {
            GptSessionContent gptSessionContent = new GptSessionContent();
            gptSessionContent.setSessionId(sessionId);
            gptSessionContent.setContent(messageContentDto.getContent());
            gptSessionContent.setRole(messageContentDto.getRole());
            gptSessionContent.setChatType(chatType.name());
            return gptSessionContent;
        }).toList();
    }

    public List<GptSessionContent> cover(String sessionId, String userId){
        return this.messages.stream().map(messageContentDto -> {
            GptSessionContent gptSessionContent = new GptSessionContent();
            gptSessionContent.setSessionId(sessionId);
            gptSessionContent.setContent(messageContentDto.getContent());
            gptSessionContent.setRole(messageContentDto.getRole());
            gptSessionContent.setChatType(chatType.name());
            gptSessionContent.setCreateUser(userId);
            return gptSessionContent;
        }).toList();
    }

    public List<GptSessionContent> cover(){
        return this.messages.stream().map(messageContentDto -> {
            GptSessionContent gptSessionContent = new GptSessionContent();
            gptSessionContent.setContent(messageContentDto.getContent());
            gptSessionContent.setRole(messageContentDto.getRole());
            gptSessionContent.setChatType(chatType.name());
            return gptSessionContent;
        }).toList();
    }
}
